package cn.rkylin.oms.system.supplier.service;

import cn.rkylin.apollo.common.util.SnoGerUtil;
import cn.rkylin.oms.common.dto.PagedData;
import cn.rkylin.oms.system.supplier.dao.ISupplierDao;
import cn.rkylin.oms.system.supplier.domain.SearchConditions;
import cn.rkylin.oms.system.supplier.domain.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service("supplierService")
public class SupplierServiceImpl implements ISupplierService {

    @Autowired
    private ISupplierDao supplierDao;

    @Override
    public Supplier create(Supplier supplier) throws Exception {
        supplier.setId(SnoGerUtil.getUUID());
        supplier.setCreateTime(new Date());
        supplier.setUpdateTime(new Date());
        supplierDao.create(supplier);
        return supplier;
    }

    @Override
    public Supplier update(Supplier supplier) throws Exception {
        supplier.setUpdateTime(new Date());
        supplierDao.update(supplier);
        return supplier;
    }

    @Override
    public void delete(String id) throws Exception {
        supplierDao.delete(id);
    }

    @Override
    public PagedData<Supplier> search(Pageable pageable, SearchConditions conditions) throws Exception {
        return supplierDao.search(pageable, conditions);
    }

    @Override
    public PagedData<Supplier> search(Pageable pageable, Map<String, Object> conditions) throws Exception {
        return supplierDao.search(pageable, conditions);
    }
    
    /**
     * 得到供应商列表
     * 
     * @param supplier 供应商bean
     * @return 供应商列表
     * @throws Exception 异常
     */
    public List<Supplier> getSupplierList(Supplier supplier) throws Exception {
        return supplierDao.getSupplierList(supplier);
    }
    
}
